package com.app.twth.app;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.app.twth.ui.login.LoginActivity;
import com.app.twth.utils.PreferencesUtil;


/**
 * App Router
 * APP路由，Activity跳转等操作在这包装好方法
 */
public class AppRouter {
    public static String K_EXTRA = "k_extra";

    public static void showFragmentActivity(Context context, Class c) {
        showFragmentActivity(context, c, null);
    }

    public static void showFragmentActivity(Context context, Class c, Bundle bundle) {
        Intent intent = new Intent(context, c);
        intent.putExtra(K_EXTRA, bundle);
        context.startActivity(intent);
    }

    public static void showActivityForResult(Activity activity, Class c, Bundle bundle, int num) {
        Intent intent = new Intent(activity, c);
        intent.putExtra(K_EXTRA, bundle);
        activity.startActivityForResult(intent, num);
    }

    public static void setLogin(Context context) {
        PreferencesUtil.putString(context, Constant.token, "");
        PreferencesUtil.putString(context, Constant.location, "");
        MyApplication.token = "";
        showFragmentActivity(context, LoginActivity.class);
    }

    public static void showClassActivity(Context context, String c) {
        showClassActivity(context, c, null);
    }

    public static void showClassActivity(Context context, String c, Bundle bundle) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(context.getPackageName(), c));
        intent.putExtra(K_EXTRA, bundle);
        context.startActivity(intent);
    }

    public static void showClassActivityForResult(Activity activity, String c, Bundle bundle, int num) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(activity.getPackageName(), c));
        intent.putExtra(K_EXTRA, bundle);
        activity.startActivityForResult(intent, num);
    }
}
